<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>

<body>
    <div id="app">
        <div>
            {{arr}}
            <button @click="changeArr">改变数组</button>
        </div>
        <div>
            {{obj}}
            <button @click="changeObj">改变对象</button>
        </div>
    </div>
</body>
<script>
    let app = new Vue({
        el: '#app',
        data: {
            arr: [1, 2, 3],
            obj: { a: 1 }
        },
        methods: {
            changeArr() {
                // (改变的数组,改变的下标,改变后的值)
                Vue.set(this.arr, 1, 999)

            },
            changeObj() {
                // 对象可以改变不能直接新增
                // (改变的对象,增加的属性,增加的值)
                this.$set(this.obj, 'b', '彭于晏')
            },
        }
    })
</script>

</html>